using UnityEngine;

public class ItemObject : MonoBehaviour
{
    private Rigidbody2D rb;
    private SpriteRenderer sr;
    [SerializeField] private ItemData item;

    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
        sr = GetComponent<SpriteRenderer>();

    }

    public void SetupItem(ItemData item, Vector2 velocity)
    {
        this.item = item;
        rb.velocity = velocity;
        SetupVisuals();
    }

    public void PickupItem()
    {
        if (!Inventory.Instance.CanAddItem() && item.ItemType == ItemType.Equipment)
        {
            rb.velocity = Vector2.up * 5f; // Throw the item up if inventory is full
            PlayerManager.Instance.Player.Fx.CreatePopUp("Inventory is full");
            return;
        }
        AudioManager.Instance.PlaySfx(18, transform);
        Inventory.Instance.AddItem(item);
        Destroy(gameObject);
    }

    private void SetupVisuals()
    {
        sr.sprite = item.ItemIcon;
        gameObject.name = $"Item object - {item.ItemName}";
    }
}
